﻿using System;
using System.Data;
using SQLHelper;
public partial class admin_News_Create : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bind();
        }
    }

    protected void Create(object sender, EventArgs e)
    {
        string column_name = DropDownList1.SelectedValue;
        string title = TextBox1.Text.ToString().Trim();
        string contents = TextBox3.Text.ToString().Trim();
        string writer = this.Label1.Text.ToString();
        string socure = TextBox2.Text.ToString().Trim();
        string user_id = Label2.Text.ToString();
        DateTime create_at = DateTime.Now;
        string sql = "insert into news (column_name,title,contents,writer,source,user_id,created_at) values('" + column_name
            + "','" + title
            + "','" + contents
            + "','" + writer
            + "','" + socure
            + "','" + user_id
            + "','" + create_at
            + "')";
        //Response.Write(sql);
        DB.GetDataNoQuery(sql);
        DB.ColseSqlCon();
        Response.Redirect("~/admin/News/Default.aspx");
    }

    void bind()
    {
        string sql = "select column_name from columns";
        DataSet res = DB.GetDataWithQuerySecond(sql, "columns");
        DropDownList1.DataTextField = "column_name";
        DropDownList1.DataValueField = "column_name";
        DropDownList1.DataSource = res;
        DropDownList1.DataBind();
        DB.ColseSqlCon();
    }
}